package com.hiwan.system.util;

import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.SecureRandom;

public class GenRSAKeys {
	
	private static String KEY_INSTANCE = "RSA";
	private static String randomString = "hiwan_2016_05_30_14:33:15";
	
	public static void main(String[] args) throws Exception {
		//创建密匙生成器
		KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(KEY_INSTANCE);
		//强随机数生成器
		SecureRandom secureRandom = new SecureRandom(randomString.getBytes());
		keyPairGenerator.initialize(1024, secureRandom);
		KeyPair keyPair = keyPairGenerator.genKeyPair();
		byte[] publicKeyBytes = keyPair.getPublic().getEncoded();
		System.out.println("生成公匙：");
		System.out.println(Base64.encode(publicKeyBytes));
		byte[] privateKeyBytes = keyPair.getPrivate().getEncoded();
		System.out.println("生成私匙：");
		System.out.println(Base64.encode(privateKeyBytes));
	}
}
